package pyip.lib.mixtool.util;

import java.awt.Toolkit;
import javax.swing.UIManager;

public class OS {

    private static String os;
    static {
        os = System.getProperty("os.name").toLowerCase();
    }

    public static String getOSName() {
        return os;
    }

    private static final boolean osIsWindows = (os != null) && (os.indexOf("windows") != -1);
    private static final boolean osIsWindowsXP = "windows xp".equals(os);
    private static final boolean osIsWindows2003 = "windows 2003".equals(os);
    private static final boolean osIsWindowsVista = "windows vista".equals(os);
    private static final boolean osIsWindows7 = "Windows 7".equals(os);
    private static final boolean osIsMacOsX = "mac os x".equals(os);
    private static final boolean osIsLinux = (os != null) && (os.indexOf("linux") != -1);

    public static boolean isWindows() {
        return osIsWindows;
    }

    public static boolean isWindowsXP() {
        return osIsWindowsXP;
    }

    public static boolean isWindows2003() {
        return osIsWindows2003;
    }

    public static boolean isWindowsVista() {
        return osIsWindowsVista;
    }

    public static boolean isWindows7() {
        return osIsWindows7;
    }

    public static boolean isMacOSX() {
        return osIsMacOsX;
    }

    public static boolean isLinux() {
        return osIsLinux;
    }

    public static boolean isUsingWindowsVisualStyles() {
        if (!isWindows()) {
            return false;
        }

        boolean xpthemeActive = Boolean.TRUE.equals(Toolkit.getDefaultToolkit().getDesktopProperty("win.xpstyle.themeActive"));

        if (!xpthemeActive)
            return false;
        try {
            return System.getProperty("swing.noxp") == null;
        } catch (RuntimeException e) {
        }
        return true;
    }

    public static String getWindowsVisualStyle() {
        String style = UIManager.getString("win.xpstyle.name");
        if (style == null) {
            style = (String) Toolkit.getDefaultToolkit().getDesktopProperty("win.xpstyle.colorName");
        }

        return style;
    }

}